// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import "forge-std/Test.sol";
import "../src/CPFundToken.sol";
import "../src/IdentityRegistry.sol";
import "../src/Compliance.sol";
import "../src/CPFundICO.sol";
import "forge-std/console.sol";


contract CPFundICOTest is Test {
    CPFundICO public ico;
    CPFundToken public token;
    IdentityRegistry public identityRegistry;
    Compliance public compliance;
    address public owner;
    address public user1;
    address public user2;

    uint256 public constant INITIAL_SUPPLY = 1_000_000 ether; // 100 万代币
    uint256 public constant RATE = 1000; // 1 ETH = 1000 代币
    uint256 public constant CAP = 100 ether; // 100 ETH 募资上限
    uint256 public constant LOCK_DAYS = 90; // 默认锁定 90 天

    // function setUp() public {
    //     owner = vm.addr(1);
    //     user1 = vm.addr(2);
    //     user2 = vm.addr(3);

    //     // 部署合约
    //     vm.prank(owner);
    //     token = new CPFundToken();
    //     compliance = new Compliance();
    //     identityRegistry = new IdentityRegistry();

    //     vm.prank(owner);
    //     token.initialize("CP Fund Token", "CPC", 6, owner, INITIAL_SUPPLY, address(identityRegistry), address(compliance));

    //     vm.prank(owner);
    //     ico = new CPFundICO();
    //     vm.prank(owner);
    //     ico.initialize(address(token), owner, address(compliance), RATE, CAP, LOCK_DAYS);

    //     // 让 ICO 合约能够铸造代币
    //     vm.prank(owner);
    //     token.transferOwnership(address(ico));
    // }

    // function testInitialState() public {
    //     assertEq(ico.rate(), RATE, "Incorrect initial rate");
    //     assertEq(ico.cap(), CAP, "Incorrect cap");
    //     assertEq(ico.isICOActive(), false, "ICO should not be active initially");
    //     assertEq(ico.lockDays(), LOCK_DAYS, "Incorrect lock days");
    // }

    // function testStartAndEndICO() public {
    //     vm.prank(owner);
    //     ico.startICO();
    //     assertEq(ico.isICOActive(), true, "ICO should be active");

    //     vm.prank(owner);
    //     ico.endICO();
    //     assertEq(ico.isICOActive(), false, "ICO should be inactive");
    // }

    // function testBuyTokensWithETH() public {
    //     vm.prank(owner);
    //     ico.startICO();

    //     vm.deal(user1, 10 ether); // 给予 user1 10 ETH
    //     vm.prank(user1);
    //     ico.buyTokensWithETH{value: 1 ether}(); // 购买 1 ETH 价值的代币

    //     assertEq(token.balanceOf(user1), 1000 ether, "User did not receive the correct amount of tokens");
    //     assertEq(address(ico).balance, 1 ether, "ICO contract did not receive ETH");
    // }

    // function testSetLockDays() public {
    //     vm.prank(owner);
    //     ico.setLockDays(180);
    //     assertEq(ico.lockDays(), 180, "Lock days not updated");
    // }

    // function testCannotBuyTokensWhenICOInactive() public {
    //     vm.expectRevert("ICO is not active");
    //     vm.prank(user1);
    //     ico.buyTokensWithETH{value: 1 ether}();
    // }

    // function testWithdrawFunds() public {
    //     vm.prank(owner);
    //     ico.startICO();

    //     vm.deal(user1, 5 ether);
    //     vm.prank(user1);
    //     ico.buyTokensWithETH{value: 5 ether}();

    //     uint256 ownerBalanceBefore = owner.balance;
    //     vm.prank(owner);
    //     ico.withdrawFunds();
    //     assertGt(owner.balance, ownerBalanceBefore, "Owner should receive funds");
    // }
}
